package com.cspg.design.presenter;

import android.app.Activity;
import android.content.Intent;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.cspg.design.CSPGApplication;
import com.cspg.design.MainActivity;
import com.cspg.design.bean.UserInfo;
import com.cspg.design.bean.shemeBean.MyHighVoltageSchemeBean;
import com.cspg.design.bean.shemeBean.MyLowVoltageSchemeBean;
import com.cspg.design.dao.gen.DaoSession;
import com.cspg.design.dto.MyHighVoltageSchemeDto;
import com.cspg.design.dto.MyLowVoltageSchemeDto;
import com.cspg.design.request.PointDevice;
import com.cspg.design.request.Scheme;
import com.cspg.design.ui.login.LoginActivity;
import com.cspg.design.ui.schemeActivity.MySchemeActivity;
import com.cspg.design.widget.CSPGProgressBar;
import com.cspg.design.widget.ToastUtils;
import com.google.common.collect.Lists;

import java.util.ArrayList;
import java.util.List;

import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action1;

public class PointDeviceInfoPresenter implements IPresenter {
    private PointDevice pointDevice;
    private Activity activity;

    private DaoSession daoSession;

    private CSPGProgressBar cspgProgressBar;
    

    public PointDeviceInfoPresenter(Activity activity) {
        this.pointDevice = new PointDevice(this);
        this.activity = activity;
        this.daoSession = ((CSPGApplication)activity.getApplication()).getDaoSession();
    }

    public  void  getPointDeviceInfo()
    {
        if(cspgProgressBar == null)
        {
            cspgProgressBar = CSPGProgressBar.show(activity);
        }else {
            cspgProgressBar.show();
        }
        try {
            pointDevice.getPointDeviceInfo();
        }catch (Exception e)
        {
            e.printStackTrace();
        }
    }

    public void getFailure(String msg) {

        if (null != cspgProgressBar && cspgProgressBar.isShowing()) {
            cspgProgressBar.dismiss();
        }
        ToastUtils.toast(activity, msg);
    }

    public void getTokenExpireFailure() {

        if (null != cspgProgressBar && cspgProgressBar.isShowing()) {
            cspgProgressBar.dismiss();
        }
        Intent intent = new Intent();
        intent.setClass(activity, LoginActivity.class);
        activity.startActivity(intent);
    }

    public void requestHighSuccess(MyHighVoltageSchemeDto myHighVoltageSchemeDto) {
        if (myHighVoltageSchemeDto != null) {

        }
    }

    public void requestHighSuccess(List<MyHighVoltageSchemeDto> myHighVoltageSchemeDtos) {
        if (myHighVoltageSchemeDtos != null) {
//            processHighData(myHighVoltageSchemeDtos);
        }
    }

    public void updateHighSuccess() {
        MyHighVoltageSchemeDto myHighVoltageSchemeDto = null;
        if (myHighVoltageSchemeDto != null) {

        }
    }
    public void requestLowSuccess(MyLowVoltageSchemeDto myLowVoltageSchemeDto) {
        if (myLowVoltageSchemeDto != null) {

        }
    }

    public void requestLowSuccess(List<MyLowVoltageSchemeDto> myLowVoltageSchemeDtos) {
        if (myLowVoltageSchemeDtos != null) {
//            processLowData(myLowVoltageSchemeDtos);
        }
    }


    @Override
    public void netWorkError(String netError) {

        if (null != cspgProgressBar && cspgProgressBar.isShowing()) {
            cspgProgressBar.dismiss();
        }
        ToastUtils.toast(activity, netError);
        if (activity instanceof MainActivity) {
            //activity.openNewActivity(LoginActivity.class);
            Intent intent = new Intent();
            intent.setClass(activity, LoginActivity.class);
            activity.startActivity(intent);
        }
    }

    @Override
    public void httpRequestFailure(String noDataError) {
        if (null != cspgProgressBar && cspgProgressBar.isShowing()) {
            cspgProgressBar.dismiss();
        }
        ToastUtils.toast(activity, noDataError);
        if (activity instanceof MainActivity) {
            //activity.openNewActivity(LoginActivity.class);
            Intent intent = new Intent();
            intent.setClass(activity, LoginActivity.class);
            activity.startActivity(intent);
        }
    }

    @Override
    public void httpRequestSuccess() {
        if (null != cspgProgressBar && cspgProgressBar.isShowing()) {
            cspgProgressBar.dismiss();
        }
    }
   
}
